home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / applescriptMode.tcl < prev    next >
Encoding:
Text File  |  1999-01-27  |  2.6 KB  |  71 lines  |  [TEXT/ALFA]

  1. #############################################################################
  2. # AppleScript.tcl
  3. #  John Sarapata
  4. #  sarapata_john@jpmorgan.com
  5. #
  6. # Description:
  7. #    This file implements an AppleScript mode, for people who wish Script
  8. #    Editor had complex functions like search and replace. Currently, it
  9. #    only supports color editing and function finding, but I may extend it.
  10. #
  11. #    I have not found a way to distinguish function definitions from
  12. #    on error constructs, so I assume that any "on name" statements at
  13. #    the beginning of the line are definitions. Script Editor saves files
  14. #    in this format, so you will only need to be careful when creating
  15. #    functions in Alpha.
  16. #############################################################################
  17.  
  18. alpha::mode Scrp 1.0.1 dummyScrp {*.script} {electricBraces electricTab}
  19.  
  20. #===============================================================================
  21. #    Set up the mode variables
  22. newPref    v wordWrap {0} Scrp
  23. newPref    f autoMark {0} Scrp
  24. newPref    v prefixString {--} Scrp
  25. newPref    v leftFillColumn {3} Scrp
  26. newPref    v funcExpr {^(on)[ \t]+(\w+)} Scrp
  27. newPref    v parseExpr {^[^ \t]+[ \t]+(\w+)} Scrp
  28. newPref    v wordBreak {\w+} Scrp
  29. newPref    v wordBreakPreface {\W} Scrp
  30.  
  31. proc dummyScrp {} {}
  32.  
  33. #===============================================================================
  34. #    Set up comments and keywords
  35. set scriptKeyWords {
  36.     on end error global local return it me pi result space tab close copy 
  37.     count data size delete duplicate exists get launch make move open print 
  38.     quit run save in of is after before div mod and not or start starts 
  39.     begin begins end ends contains does equal equals greater less than as 
  40.     reference set try tell if repeat else then times while until with by 
  41.     considering ignoring timeout transaction script property prop first 
  42.     second third fourth fifth sixth seventh eighth ninth tenth last front 
  43.     back middle every some from to through thru
  44. }
  45.  
  46. regModeKeywords -e {--} -b {\(*} {*\)} -c red -k blue Scrp $scriptKeyWords
  47.  
  48. unset scriptKeyWords
  49.  
  50. #===============================================================================
  51. #    File Marking
  52. proc Scrp::MarkFile {} {
  53.     global ScrpmodeVars
  54.     set pos [minPos]
  55.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $ScrpmodeVars(funcExpr) $pos} res]} {
  56.     set start [lindex $res 0]
  57.     set end [lindex $res 1]
  58.     set text [lindex [split [getText $start $end]] 1]
  59.     set pos $end
  60.     set inds($text) $res
  61.     }
  62.     
  63.     if {[info exists inds]} {
  64.     foreach f [lsort [array names inds]] {
  65.         setNamedMark $f [lineStart [pos::math [lineStart [lindex $inds($f) 0]] - 1]] \
  66.           [lindex $inds($f) 0] [lindex $inds($f) 1]
  67.     }
  68.     }
  69. }
  70.  
  71.